import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class StockService {
  constructor() { }

  private stocks: Stock[] = [
    new Stock(1, "第一只股票", 14, 2, "第1只股票的描述", ["IT","互联网"]),
    new Stock(2, "第二只股票", 24, 2.5, "第2只股票的描述", ["IT","金融"]),
    new Stock(3, "第三只股票", 34, 3.5, "第3只股票的描述", ["金融"]),
    new Stock(4, "第四只股票", 44, 4, "第4只股票的描述", ["IT"]),
    new Stock(5, "第五只股票", 54, 4.5, "第5只股票的描述", ["互联网"]),
    new Stock(6, "第六只股票", 64, 5, "第6只股票的描述", ["IT","金融"]),
    new Stock(7, "第七只股票", 74, 4, "第7只股票的描述", ["互联网","金融"]),
    new Stock(8, "第八只股票", 84, 3, "第8只股票的描述", ["IT","金融"]),
  ];

  getStocks(): Stock[] {
    return this.stocks;
  }
  getStock(id: number): Stock {
    return this.stocks.find(stock => stock.id == id );
  }

}
export class Stock {
  constructor(
    public id: number,
    public name: string,
    public price: number,
    public rating: number,
    public desc: string,
    public cateqories: Array<string>
  ) { }
}
